package com.typy.www.tpay.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.typy.www.tpay.bean.vm.NoticeVm;
import com.typy.www.tpay.ui.itemview.NoticeItemView;

import java.util.List;

/**
 * Created by 13799 on 2018/6/22.
 */

public class NoticeAdapter extends BaseAdapter {

    private List<NoticeVm> data;
    private Context mContext;
    public NoticeAdapter(Context context){
        mContext=context;
    }

    public void setData(List<NoticeVm> data) {
        this.data = data;
    }

    @Override
    public int getCount() {
        return data==null?0:data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        NoticeItemView itemView=null;
        if(convertView==null){
            itemView= new NoticeItemView(mContext);
            convertView=itemView.getView();
            convertView.setTag(itemView);
        }else {
            itemView= (NoticeItemView) convertView.getTag();
        }
        itemView.bind(data.get(position),position);
        return convertView;
    }
}
